package com.rongke.web.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.rongke.commons.JsonResp;
import com.rongke.commons.PageDto;
import com.rongke.model.Channel;
import com.rongke.model.EachPicture;
import com.rongke.model.Information;
import com.rongke.model.TransactionData;
import com.rongke.service.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @EachPictureController
 * @广告Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/eachPicture")
@Transactional
@CrossOrigin
public class EachPictureController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private EachPictureService eachPictureService;
   @Autowired
   private InformationService  informationService;
   @Autowired
   private TransactionDataService transactionDataService;
   @Autowired
   private UserService userService;
   @Autowired
   private ChannelService channelService;
   @Autowired
   private CashRecordService cashRecordService;
   @Autowired
   private UserAuthMsgService userAuthMsgService;
   @Autowired
   private OptionOrderService optionOrderService;
    /**
     * @添加广告
     * @param eachPicture
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addEachPicture(@RequestBody EachPicture eachPicture){
        log.debug("添加广告");
        eachPictureService.insert(eachPicture);
        return JsonResp.ok(eachPicture);
    }

    /**
     * @修改广告
     * @param eachPicture
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateEachPicture(@RequestBody EachPicture eachPicture){
        log.debug("修改广告");
        eachPictureService.updateById(eachPicture);
        return JsonResp.ok(eachPicture);
    }
    /**
     * @根据id查找广告
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectEachPicture(Long id){
        log.debug("查找广告");
        EachPicture eachPicture = eachPictureService.selectById(id);
        return JsonResp.ok(eachPicture);
    }

/**
 * 删除
 * */
    @RequestMapping(value="/delceteach", method = RequestMethod.GET)
    public JsonResp delceteach(Long id){
        log.debug("修改广告");
       Boolean booo= eachPictureService.deleteById(id);
        return JsonResp.ok(booo);
    }


    /**
    * 主页展示
    * */

    /**
     * 主页查询 后台的咨询和期权也是调用这个
     * type null 查询轮播图 和咨询 1 股票咨询 2,期权交易
     * */
    @RequestMapping(value = "/Homepagequery",method = RequestMethod.GET)
    public JsonResp  Homepagequery(Page page,Information information,TransactionData transactionData,Integer types){
        EntityWrapper<EachPicture> eachPictureWrapper=new EntityWrapper<EachPicture>();
        eachPictureWrapper.orderBy("upt_datetime");
        Map map=new HashMap();
        map.put("pageNo",(page.getCurrent()-1)*page.getSize());
        map.put("pageSize",page.getSize());
        map.put("information",information);
        map.put("transactionData",transactionData);
        List<EachPicture> listeachpicture=null;
        List<Information> informationList=null;
        Integer sunm=null;
        Integer qiquan=null;
        List<TransactionData>  TeanList=null;
        Map maps=new HashMap();
        if(types==null){
              listeachpicture=eachPictureService.selectList(eachPictureWrapper); //主页轮播图
              informationList=informationService.selectInfolist(map);
              sunm=informationService.selectInfolistCount(map);
            maps.put("listeachpicture",listeachpicture); //轮播图
            maps.put("informationList",new PageDto(page.getCurrent(),page.getSize(),informationList,sunm)); //股票咨询
            maps.put("ZXCOUNT",sunm); //总个数
         }else if (types==1){
            informationList=informationService.selectInfolist(map);
            sunm=informationService.selectInfolistCount(map);
            maps.put("informationList",new PageDto(page.getCurrent(),page.getSize(),informationList,sunm)); //股票咨询
            maps.put("ZXCOUNT",sunm); //总个数
        }else if (types==2){
            TeanList=transactionDataService.selctetAll(map);
            qiquan=transactionDataService.selectAllCount(map);
            maps.put("QQCOUNT",qiquan);
            maps.put("TeanList",new PageDto(page.getCurrent(),page.getSize(),TeanList,qiquan)); //期权交易
        }
        return JsonResp.ok(maps);
    }

    /***
     * @后台主页
     * */
     @RequestMapping(value = "/Backstagehomepage",method = RequestMethod.GET)
    public JsonResp Backstagehomepage(){
         Map mapss=new HashMap();
           /**会员总数**/
         EntityWrapper ewtiy=new EntityWrapper();
         ewtiy.ne("status",3);
         Integer  userList=userService.selectCount(ewtiy);
         mapss.put("HYZS",userList);
         /**今日新增会员*/
         Integer XZHY=userService.selectUserListcont();
         mapss.put("XZHY",XZHY);
         /**代理总数*/
          EntityWrapper<Channel> channelEntityWrapper=new EntityWrapper<>();
          channelEntityWrapper.eq("status",1);
         Integer DLZS=channelService.selectCount(channelEntityWrapper);
         mapss.put("DLZS",DLZS);
         /**今日新增代理*/
          Integer JRXZDL=channelService.newagent();
         mapss.put("JRXZDL",JRXZDL);
          /**提现 审批中*/
          EntityWrapper entityWr=new EntityWrapper();
          entityWr.eq("withdraw_status",1);
          entityWr.eq("recoed_type",2);
          Integer TXSP=cashRecordService.selectCount(entityWr);
         mapss.put("TXSP",TXSP);
         /**
          * 今日提现成功人数
          */
         Integer CGRS=cashRecordService.withdrawalssuccess();
         mapss.put("CGRS",CGRS);
         /***累积提现*/
         EntityWrapper LEIJI=new EntityWrapper();
         LEIJI.eq("status",1);
         LEIJI.eq("recoed_type",2);
         LEIJI.eq("withdraw_status",2);
         Integer  LJTX=cashRecordService.selectCount(LEIJI);
         mapss.put("LJTX",LJTX);
         /**今日充值*/
        Integer JRCZ=cashRecordService.Today();
         mapss.put("JRCZ",JRCZ);
       /**累计充值*/
       EntityWrapper AGLJCZ=new EntityWrapper();
       AGLJCZ.eq("status",1);
       AGLJCZ.eq("recoed_type",1);
       Integer LJCZ=cashRecordService.selectCount(AGLJCZ);
         mapss.put("LJCZ",LJCZ);
       /**认购 待审核认证请求*/
      EntityWrapper DS=new EntityWrapper();
      DS.eq("status",1);
      Integer  DSH=optionOrderService.selectCount(DS);
         mapss.put("DSH",DSH);
         /**行权申请*/
         EntityWrapper XQSQ2=new EntityWrapper();
         XQSQ2.eq("status",3);
         Integer  XQSQ=optionOrderService.selectCount(XQSQ2);
         mapss.put("XQSQ",XQSQ);
         /** 今日新认购请求*/
  /*       Integer JRXRGQQ=optionOrderService.rightscount();
         mapss.put("JRXRGQQ",JRXRGQQ);
         *//**代理今日佣金*//*

         BigDecimal  DLCommiss=optionOrderService.DLCommission(1);
         mapss.put("DLCommiss",DLCommiss);
         *//**代理总佣金 *//*
         BigDecimal  DLZYJ=optionOrderService.DLCommission(2);*/
//         mapss.put("DLZYJ",DLZYJ);
         /**三日到行权期*/
         /**平台总利润*/
         /**平台今日利润*/
         return JsonResp.ok(mapss);
     }
}
